import { ConfigEnv, loadEnv, UserConfig } from 'vite';
import { createVitePlugins } from './build/plugin';
import { generateModifyVars } from './build/theme';
import { resolve } from './build/util';

export default ({ command, mode }: ConfigEnv): UserConfig => {
    const root = process.cwd();

    const env = loadEnv(mode, root);


    return {
        root,
        plugins: createVitePlugins(env),
        resolve: {
            alias: {
                "@": resolve('src')
            },
        },
        build: {
            terserOptions: {
                compress: {
                    keep_infinity: true,
                    // Used to delete console in production environment
                    drop_console: true,
                },
            },
            // Turning off brotliSize display can slightly reduce packaging time
            brotliSize: false,
            chunkSizeWarningLimit: 1200,
        },
        css: {
            preprocessorOptions: {
                less: {
                    modifyVars: {
                        ...generateModifyVars
                    },
                    javascriptEnabled: true,
                }
            }
        },
        optimizeDeps: {
            exclude: []
        }
    };
}
